<template>
  <div class="achievement">
    <div class="achievement-header clearfix">
      <span class="fontSty" v-if="type == 2">季度</span>
      <span class="fontSty" v-if="type == 3">年</span>
      <ul class="item fl" v-if="type == 1">
        <li
          v-for="(item, index) in items"
          :key="index"
          @click="selectItem(item.type,index,item.year)"
        >
          <span :class="[current == index ? 'cur' : '']">{{item.name}}</span>
        </li>
      </ul>
      <ul class="date fr" @click="showData">
        <li class="date_time" :class="info=='按条件查询'?'':'active'">
          <span>{{info}}</span>
          <svg-icon icon-class="icon_right" class="date-hide"></svg-icon>
        </li>
      </ul>
    </div>
    <div class="achievement-content">
      <h2
        v-show="isShow"
        style="text-align: center;color: #666;font-size: 15px; line-height: 40px;"
      >截止到昨天</h2>
      <ul class="lists">
        <li class="list-title">
          <span class="title title1">微信昵称</span>
          <span class="title title2">会员ID</span>
          <span class="title title3">个人团队业绩</span>
        </li>
        <li class="list-con" v-for="(item,index) in lists" :key="index">
          <span class="title title1">{{item.nickname}}</span>
          <span class="title title2">{{item.user_id}}</span>
          <span class="title title3">
            <b>{{item.amount}}</b>
          </span>
        </li>
        <p v-if="lists.length==0" class="no-data">
          <img :src="noDataImg" alt />
          <span>当前{{type == 1 ? '月份' : type == 2 ? '季度' : '年份'}}没有数据</span>
        </p>
      </ul>
      <date-pop
        @cancel="cancelTime"
        @confirm="selectTime"
        v-if="show_date"
        :current="type"
        :timeData="timeData"
      ></date-pop>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import 'vant/lib/index.css'
import { Popup } from 'vant'
import datePop from '@/views/user/components/datePop'
import { getDhsGljDetail } from '@/api/user/dhs/dhsApi'
import { mapGetters } from 'vuex'
Vue.use(Popup)
export default Vue.extend({
  data() {
    return {
      noDataImg: 'https://img.wifenxiao.com/h5-wfx/images/user/no-yeji-data.png',
      current: 3,
      show_date: false,
      currentYear: '',
      type: '',
      currentMonth: '',
      selectQuarter: '',
      items: [],
      isShow: true,
      lists: [],
      timeData: {},
      info: '按条件查询'
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getTime()
      this.getDhsGlj()
    },

    // 数据请求
    getDhsGlj() {
      // console.log('this.timeData', this.timeData)
      const value =
        this.type == 1
          ? this.timeData.currentMonth
          : this.type == 2
            ? this.timeData.currentQuarter
            : ''

      const data = {
        value,
        year: this.timeData.currentYear
      }
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      getDhsGljDetail(data).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.timeData.year = res.data.year_list
          this.timeData.month = res.data.month_list
          this.timeData.currentYear = res.data.year
          this.timeData.currentMonth = res.data.month
          this.timeData.quarter = res.data.quarter
          this.type = res.data.dhs_team_bonus_time_type
          this.lists = res.data.lists
        } else {
          this.$Error(res.msg)
        }
      })
    },
    selectItem(type, index, year) {
      this.current = index
      this.currentYear = year
      this.currentMonth = type
      this.timeData.currentMonth = type
      if (this.month == type) {
        this.isShow = true
      } else {
        this.isShow = false
      }
      this.getDhsGlj()
      this.info = '按条件查询'
    },
    selectTime(e) {
      this.currentYear = e.selectYear
      this.currentMonth = e.selectMonth
      this.currentQuarter = e.selectQuarter
      this.timeData.currentYear = e.selectYear
      this.timeData.currentMonth = e.selectMonth
      this.timeData.currentQuarter = e.selectQuarter
      // this.current = -1;
      this.getDhsGlj()
      // console.log('type', this.type)
      if (this.type == 1) {
        this.info = this.currentYear + '年' + this.currentMonth + '月'
        if (this.month == this.currentMonth) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      } else if (this.type == 2) {
        this.info =
          this.currentYear + '年' + '第' + this.currentQuarter + '季度'
        if (this.quarter == this.currentQuarter) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      } else {
        this.info = this.currentYear + '年'
        if (this.year == this.currentYear) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      }
      this.show_date = false
    },
    cancelTime() {
      this.show_date = false
    },
    showData() {
      this.show_date = true
    },
    // 路由跳转
    Jump(url) {
      this.$JumpPath(this, url)
    },

    // 获取当前月份和前三个月份
    getTime() {
      const time = new Date()
      const currentMonth = time.getMonth() + 1
      const currentYear = time.getFullYear()
      const currentQuarter = Math.ceil(currentMonth / 3)
      const item = [{ name: '本月', type: currentMonth, year: currentYear }]
      for (let i = 1; i <= 3; i++) {
        const month =
          currentMonth - i > 0 ? currentMonth - i : currentMonth - i + 12
        const year = currentMonth - i > 0 ? currentYear : currentYear - 1

        item.unshift({ name: month + '月', type: month, year: year })
      }
      // 当前年月
      this.currentYear = this.$route.query.year
      this.currentMonth = this.$route.query.month
      this.currentQuarter = this.$route.query.quarter
      this.timeData.currentYear = this.$route.query.year
      this.timeData.currentMonth = this.$route.query.month
      this.timeData.currentQuarter = this.$route.query.quarter
      this.type = this.$route.query.type
      this.current = this.$route.query.current
      this.year = currentYear
      this.month = currentMonth
      this.quarter = currentQuarter
      // console.log('route', this.$route.query)
      if (this.type == 1) {
        this.info = this.currentYear + '年' + this.currentMonth + '月'
      } else if (this.type == 2) {
        this.info =
          this.currentYear + '年' + '第' + this.currentQuarter + '季度'
      } else {
        this.info = this.currentYear + '年'
      }
      this.items = item
    }
  },
  components: {
    datePop
  },
  computed: {
    // 获取自定义符号
    ...mapGetters(['mSymbol'])
  }
})
</script>

<style lang="scss">
@import "src/styles/variables";
@import "src/styles/mixin";
.achievement {
  .fontSty {
    color: #f30c23;
    margin-left: 48px;
    font-size: 28px;
    line-height: 60px;
  }
  // background-color: #f4f4f4;
  min-height: 700px;
  &-header {
    background-color: $default;
    padding: 20px 0;
    margin-bottom: 20px;
    z-index: 9999;
    .item {
      display: flex;
      justify-content: space-between;
      // flex-wrap: wrap;
      width: 50%;
      margin-left: 30px;
      height: 56px;
      border: 1.5px solid $warning;
      border-radius: 28px;
      box-sizing: border-box;
      overflow: hidden;
      li {
        flex: 1;
        // height: 100%;
        text-align: center;
        border-right: 1px solid $warning;
        box-sizing: border-box;
        &:last-child {
          border-right: none;
        }
        span {
          display: inline-block;
          width: 100%;
          color: $warning;
          font-size: 22px;
          line-height: 56px;
          &.cur {
            border-right: 1px solid $warning;
            color: $default;
            background-color: $warning;
          }
        }
      }
    }
    .date {
      margin-right: 30px;
      display: inline-block;
      color: #666;
      span {
        line-height: 60px;
      }
      .date_time {
        &.active {
          color: #ff5a00;
        }
      }
      .date-hide {
        transform: rotateZ(90deg);
      }
      .date-show {
        line-height: 56px;
        span {
          color: $warning;
          font-size: 24px;
        }
      }
    }
  }
  .achievement-content {
    background-color: $default;
    box-sizing: border-box;
    border-radius: 20px;
    margin: 0 25px;
    .lists {
      overflow: hidden;
      background: #fff;
      border-radius: 20px;
      margin: 0 25px;
      padding: 0 25px;
      li {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        line-height: 120px;
        color: #333;
        box-sizing: border-box;
        border-bottom: 1px solid #ededed;
        span {
          flex: 1;
          font-size: 26px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          color: #333;
          &.title2 {
            text-align: center;
          }
          &.title3 {
            text-align: right;
            padding-right: 15px;
          }
        }
        &.list-con {
          span {
            &.title3 {
              font-weight: bold;
              color: #fd2049;
            }
          }
        }
        &:first-child {
          line-height: 95px;
        }
        &:last-child {
          border-bottom: 0;
        }
      }
      .no-data {
        padding: 150px 0 180px;
        img {
          width: 426px;
          height: 281px;
          display: block;
          margin: 0 auto;
        }
        span {
          font-size: 28px;
          color: #999999;
          display: block;
          text-align: center;
          margin-top: -100px;
        }
      }
    }
  }
  .explain {
    margin: 30px;
    .explain_click {
      color: #999;
      font-size: 24px;
    }
    .icon {
      display: inline-block;
      width: 48px;
      height: 48px;
      line-height: 48px;
      font-size: 28px;
      text-align: center;
      border: 2px solid $warning;
      color: $warning;
      font-weight: bold;
      border-radius: 50%;
      transform: scale(0.5, 0.5);
      margin-left: -16px;
    }
  }
}
.Glossary {
  margin-top: 30px;
  padding-left: 30px;
  li {
    padding: 24px 0;
    border-bottom: 1px solid #f4f4f4;
    box-sizing: border-box;
    p {
      width: 710px;
      line-height: 48px;
      color: #333;
      font-size: 28px;
      &:nth-child(2) {
        color: #999;
        font-size: 24px;
      }
    }
  }
}
.ok {
  background-color: $warning;
  text-align: center;
  margin: 30px;
  margin-top: 20px;
  border-radius: 42px;
  span {
    line-height: 84px;
    color: $default;
    font-size: 30px;
  }
}
</style>
